package ch.didierviret.memgest.shared.entities;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;

import com.google.appengine.api.datastore.Key;

/**
 * Join many Persons with many PersonsGroups in a many to many relation
 */
@SuppressWarnings("serial")
@Entity
public class Membership implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key key;

	@Version
	private int version;

	// // Relation with the person concerned by this Membership
	// @ManyToOne(fetch = FetchType.LAZY)
	// private Person person;
	//
	// // Relation with the group concerned by this Membership
	// @ManyToOne(fetch = FetchType.LAZY)
	// private PersonsGroup personsGroup;

	public Membership() {
		super();
	}

	// TODO Test method, to be deleted
	public String toString() {
		String myString;

		if (this.key != null) {
			myString = Long.toString(key.getId());
		} else {
			myString = "";
		}
		myString += ", " + Integer.toString(getVersion());

		return myString;
	}

	// public Person getPerson() {
	// return person;
	// }
	//
	// public void setPerson(Person person) {
	// this.person = person;
	// }
	//
	// public PersonsGroup getPersonsGroup() {
	// return personsGroup;
	// }
	//
	// public void setPersonsGroup(PersonsGroup personsGroup) {
	// this.personsGroup = personsGroup;
	// }

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public int getVersion() {
		return version;
	}
}
